<template>
  <!-- 后台通用布局主容器 -->
  <div class="admin-layout">
    <!-- 顶部导航栏 -->
    <el-header class="admin-header">
      <span class="logo">企业后台管理</span>
      <el-button type="danger" size="small" @click="logout">退出登录</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏导航 -->
      <el-aside width="180px" class="admin-aside">
        <el-menu :default-active="activeMenu" router>
          <el-menu-item index="/admin">首页</el-menu-item>
          <el-menu-item index="/admin/products">产品管理</el-menu-item>
          <el-menu-item index="/admin/news">新闻管理</el-menu-item>
          <el-menu-item index="/admin/cases">案例管理</el-menu-item>
          <el-menu-item index="/admin/partners">合作伙伴管理</el-menu-item>
          <el-menu-item index="/admin/contact">表单管理</el-menu-item>
          <el-menu-item index="/admin/users">用户管理</el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 主内容区 -->
      <el-main class="admin-main">
        <slot />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { ref, watch } from 'vue'
const router = useRouter()
const route = useRoute()
// 当前激活菜单
const activeMenu = ref(route.path)
// 监听路由变化，自动高亮菜单
watch(() => route.path, (val) => { activeMenu.value = val })
// 退出登录
function logout() {
  if (process.client) {
    localStorage.removeItem('isAdminLogin')
  }
  router.push('/admin/login')
}
</script>

<style scoped>
.admin-layout {
  min-height: 100vh;
}
.admin-header {
  background: #222;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30px;
  height: 60px;
}
.logo {
  font-size: 20px;
  font-weight: bold;
}
.admin-aside {
  background: #f5f5f5;
  min-height: calc(100vh - 60px);
}
.admin-main {
  padding: 30px;
  background: #fff;
  min-height: calc(100vh - 60px);
}
</style> 